// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import promise from 'es6-promise'
import { get, post } from './http'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/public/style.css'
import '@/assets/public/animate.css'
import '@/assets/iconfont/iconfont.css'
import {newData} from '@/assets/public/common'
import VueI18n from 'vue-i18n'
import Croppa from 'vue-croppa'
import vueDragDrag from 'vue-dragdrag'
import vueSignature from 'vue-signature'

Vue.use(ElementUI)
Vue.use(VueI18n)
Vue.use(Croppa)
Vue.use(vueDragDrag)
Vue.use(vueSignature)

Vue.prototype.$get = get
Vue.prototype.$post = post
Vue.prototype.$new = newData
Vue.config.productionTip = false
// axios兼容ie9
promise.polyfill()

// 国际化处理
const i18n = new VueI18n({
  locale: 'CN', // 语言标识
  messages: {
    'CN': require('@/assets/languages/cn'), // 中文语言包
    'US': require('@/assets/languages/us') // 英文语言包
  }
})

// 路由拦截
router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) { // 判断是否需要登录权限
    if (store.state.isLogin) {
      next()
    } else {
      next({
        name: 'UserLogin'
      })
      store.commit('changeLogin', false)
      store.commit('onActive', '')
    }
  } else {
    next()
  }
})

Vue.config.productionTip = false

/* eslint-disable no-new */
let app = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  components: { App },
  template: '<App/>'
})

window.mountApp = () => {
  app.$mount('#app')
}
if (window.STYLE_READY) {
  window.mountApp()
}
